<template>
	<w-dailog v-model="dialogVisible" width="1200px" title="关联工位" heightFullscreen>
		<div class="create-organ">
			<w-transfer
				v-model="listSelectIds"
				:tableColumn="tableColumn"
				:tableData="tableData"
				:searchProps="searchProps"
				leftTitle="全部工位"
				rightTitle="选定工位"
			></w-transfer>
		</div>
		<template slot="footer">
			<el-button v-if="selectStation" type="primary" @click="copyStation">复 制</el-button>
			<el-button @click="onCancelClick">取消</el-button>
			<el-button type="primary" @click="onSaveClick">保存</el-button>
		</template>
	</w-dailog>
</template>
<script>
export default {
	name: 'workshop',
	props: {
		selectStation: {
			type: String,
			default: ''
		}
	},
	data () {
		return {
			dialogVisible: false,
			treeCheckedKeys: [],
			tableColumn: [
				{ prop: 'code', label: '工位编号', required: true, width: '80px' },
				{ prop: 'name', label: '工位名称', required: true },
				{ prop: 'stationTypeName', label: '工位类型', required: true }
			],
			tableData: [],
			tableSearchKey: '',
			listSelectIds: [],
			searchProps: ['code', 'name', 'stationTypeName']
		}
	},
	created () {
	},
	methods: {
		open (id, workKindIds, productionLineId) {
			this.listSelectIds = []
			this.findWorkKindAndTypeListAllByType(id, 2, productionLineId).then(res => {
				this.tableData = res.map(m => {
					return {
						code: m.code,
						id: m.stationId,
						name: m.name,
						workKindTypeName: m.workKindTypeName,
						sign: m.sign,
						completeSign: m.completeSign
					}
				})
				// 获取穿梭框 右侧已绑定的
				this.listSelectIds = workKindIds.map(d => {
					return d.id
				})
				this.dialogVisible = true
			})
		},
		onSaveClick () {
			const selKinds = []
			this.listSelectIds.forEach(item => {
				this.tableData.forEach(all => {
					if (all.id === item) {
						selKinds.push(all)
					}
				})
			})
			this.dialogVisible = false
			this.$emit('on-save-station', selKinds)
		},
		onCancelClick () {
			this.dialogVisible = false
		},
		findWorkKindAndTypeListAllByType (id, type, productionLineId) {
			var query = {
				type: type,
				id: id
			}
			if (productionLineId) {
				query.productionLineId = productionLineId
			}
			return new Promise(resolve => {
				this.$fxApi('workKind.findStationAllByWorkKindId')({
					query: query
				}).then(res => {
					resolve(res)
				})
			})
		},
		copyStation () {
			this.$emit('on-copy-station')
		}
	}
}
</script>
<style lang="stylus" scoped>
@import '~$assets/stylus/varsty.styl';
.create-organ {
	flex: 1
	display: flex;
	flex-direction: row;
	overflow: auto;
	width: 100%
}
</style>

